<template>
  <div class="test">
    <RenderTable 
      ref='renderTable'
      :superQueryFieldList="superQueryFieldList" 
      :queryParamArr = "queryParamArr"
      :defColumns="defColumns"
      :url = "url"
      :isShowRowSelection='false'
      @handleEdit = "handleEdit"
    >
      <template v-slot:action = '{record}'>
        <a @click="handleEdit(record)">编辑</a>        
      </template>
      <template slot="btn">
        <p-button style="margin-right: 10px" @click="exportHandle" type="primary"> 导出 </p-button>
      </template>
    </RenderTable>

    <PeopleInfoDetailModal ref="peopleInfoDetailModal" :peopleId="peopleId" :empno = 'empno' @handleSuccess='handleSuccess'></PeopleInfoDetailModal>
  </div>
</template>

<script type="text/javascript">
import RenderTable from '@/components/renderTable'
import PeopleInfoDetailModal from './peopleInfoDetailModal.vue'
import { getDictItemsArr, timestampToDatetime } from "@/utils/util";
import { api } from "@/api/manage";

const superQueryFieldList =
[
  {
    value: "organization",
    text: "组织",
    type: "String",
  },  
  {
    value: "empname",
    text: "员工姓名",
    type: "String",
  },
  {
    value: "empsex",
    text: "性别",
    dictCode: 'sex',
  },
  {
    value: "borndt",
    text: "出生年月",
    type: "date",
  },
  {
    value: "holdflg",
    text: "在职状态",
    dictCode: 'mes_holdflg',
  },
  {
    value: "registerdt",
    text: "入职日期",
    type: "date",
  },
  {
    value: "dimissidt",
    text: "离职日期",
    type: "date",
  },
  {
    value: "employNature",
    text: "雇佣性质",
    dictCode: "mes_employ_nature",
  },
  {
    value: "edulevel",
    text: "学历",
    dictCode: "mes_edulevel",
  },
  {
    value: "workroomname",
    text: "车间",
    type: "String",
  },
  {
    value: "linename",
    text: "线体",
    type: "String",
  },
  {
    value: "mobilePhone",
    text: "手机",
    type: "String",
  },
  {
    value: "duty",
    text: "岗位",
    dictCode: "mes_duty",
  },
  {
    value: "diPower",
    text: "直接/间接人",
    dictCode: "mes_di_power",
  },
  {
    value: "email",
    text: "Email",
    type: "String",
  },
  {
    value: "classname",
    text: "班组",
    type: "String",
  },
]
export default {
  data() {
    return {
      peopleId: '',
      empno: '',
      superQueryFieldList,
      queryParamArr: [
        {
          label: "员工编号",
          placeholder: "请输入员工编号",
          type: 'input',
          key: 'empno',
          value: ''
        }
      ],
      defColumns: [
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 60,
          align: "center",
          customRender: (t, r, index) => {
            return parseInt(index) + 1;
          },
        },
        {
          title: "员工编号",
          align: "center",
          dataIndex: "empno",
        },
        {
          title: "员工姓名",
          align: "center",
          dataIndex: "empname",
        },
        {
          title: "组织",
          align: "center",
          dataIndex: "organization",
        },
        {
          title: "性别",
          align: "center",
          dataIndex: "empsex",
          customRender: (t, r, index) => {
            return this.sexKeys[t]
          }
        },
        {
          title: "出生年月",
          align: "center",
          dataIndex: "borndt",
          customRender: (t, r, index) => {
            return timestampToDatetime(t);
          },          
        },
        {
          title: "在职状态",
          align: "center",
          dataIndex: "holdflg",
          customRender: (t, r, index) => {
            return this.holdflgKeys[t]
          }          
        },
        {
          title: "入职日期",
          align: "center",
          dataIndex: "registerdt",
          customRender: (t, r, index) => {
            return timestampToDatetime(t);
          },            
        },
        {
          title: "离职日期",
          align: "center",
          dataIndex: "dimissidt",
          customRender: (t, r, index) => {
            return timestampToDatetime(t);
          },            
        },
        {
          title: "雇佣性质",
          align: "center",
          dataIndex: "employNature",
          // customRender: (t, r, index) => {
          //   return this.employNatureKeys[t]
          // }   
        },
        {
          title: "学历",
          align: "center",
          dataIndex: "edulevel",
          // customRender: (t, r, index) => {
          //   return this.edulevelKeys[t]
          // }            
        },
        {
          title: "车间",
          align: "center",
          dataIndex: "workroomname",
        },
        {
          title: "线体",
          align: "center",
          dataIndex: "linename",
        },
        {
          title: "手机",
          align: "center",
          dataIndex: "mobilePhone",
        },
        {
          title: "岗位",
          align: "center",
          dataIndex: "duty",
          customRender: (t, r, index) => {
            return this.dutyKeys[t]
          }            
        },
        {
          title: "直接/间接人",
          align: "center",
          dataIndex: "diPower",
          customRender: (t, r, index) => {
            return this.diPowerKeys[t]
          }  
        },
        {
          title: "Email",
          align: "center",
          dataIndex: "email",
        },
        {
          title: "班组",
          align: "center",
          dataIndex: "classname",
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          scopedSlots: { customRender: "action" },
        },
      ],
      // 人力分类数字字典
      manpowerClassifyKeys: {},
      // 职务分类数字字典
      dutyKeys: {},
      // 直接/间接数字字典
      diPowerKeys: {},
      // 雇佣性质数字字典
      employNatureKeys: {},
      // 学历数字字典
      edulevelKeys: {},
      // 在职状态数字字典
      holdflgKeys: {},
      // 性别数字字典
      sexKeys: {},      
      url: {
        list: '/mes-manpower/mesHrEmployeeinfo/list',
        export: '/mes-manpower/mesHrEmployeeinfo/export'
      },
    
      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 },
      },         
    }
  },
  mounted() {
    this.getAjaxGetDictItems()
  },
  methods: {

    // 获取数字字典
    getAjaxGetDictItems() {
      const arr = [
        { code: "mes_manpower_classify", key: "manpowerClassifyKeys" },
        { code: "mes_duty", key: "dutyKeys" },
        { code: "mes_di_power", key: "diPowerKeys" },
        { code: "mes_employ_nature", key: "employNatureKeys" },
        { code: "mes_edulevel", key: "edulevelKeys" },
        { code: "mes_holdflg", key: "holdflgKeys" },
        { code: "sex", key: "sexKeys" },
      ];
      getDictItemsArr(this, arr);
    },

    // 导出
    exportHandle(){
      const pageNo = this.$refs.renderTable.ipagination.current;
      const limit = this.$refs.renderTable.ipagination.pageSize;      
      window.open(api.test + this.url.export + '?pageNo=' + pageNo + '&limit=' + limit)
    },

    // 编辑成功
    handleSuccess(){
      this.$refs.renderTable.loadData()
    },

    //编辑
    handleEdit(record){
      this.peopleId = record.id
      this.empno = record.empno
      this.$nextTick( () => {
        this.$refs.peopleInfoDetailModal.showModal('edit')
      } )
    },
  },
  components: {
    RenderTable,
    PeopleInfoDetailModal    
  }
}
</script>

<style lang="less" scoped>
</style>

